package rnavigator.model;

import rnavigator.controller.*;
import rnavigator.model.IOHandler;
import rnavigator.model.Model;
import rnavigator.model.Structure;
import rnavigator.view.StructurePanel;
import rnavigator.view.View;

/**
 *
 * @author Elias la Cour
 * @Initializer class for basic startup stuff
 */
public class Initializer {

    private Structure structure = null;
    private boolean debug = false;
    Controller controller = null;
    Model model = null;
    View view = null;
    IOHandler ioHandler = null;
    StructurePanel structurePanel = null;

    public Initializer() {
    }

    public Initializer(boolean debug) {
        this.debug = debug;
    }

    protected void initialize() {
        controller = new Controller();
        model = new Model();
        view = new View();
        ioHandler = new IOHandler();
        addStructure();

        //debug bør ændres, så klasser loades med debug, og ikke først efter
        setDebug(false);
        if (debug) {
            System.out.println("Debug mode activated");
        }
    }
    //calls createStructure, then adds that structure to other classes
    public void addStructure() {
        structure = createStructure();
        System.out.println("setting structure in classes: " + structure.getBaseSequence().length);
        model.setStructure(structure);
        view.createFramework();
        view.setStructure(structure);
        
        view.repaint();
        
        System.out.println("repaint called from init.addStructure");
        //view.drawLinearFeynman();

    }

    protected Structure createStructure() {
        debug=true;
        structure = ioHandler.testcase10k();
        model.tieKnots(structure);
        if (debug) {
            System.out.println("createstructure started length is: " + structure.getBaseSequence().length);
            System.out.println("length of basesequence is "+structure.getBaseSequence().length);
//            for(String s : structure.getBaseSequence()){
//                System.out.print(s);
//            }
        }
        return structure;
    }

    /**
     * @param debug the debug to set
     */
    public void setDebug(boolean debug) {
        this.debug = debug;
        model.setDebug(debug);
        view.setDebug(debug);
        ioHandler.setDebug(debug);
    }
}
